package base.web.actions;

import org.apache.log4j.Logger;

import base.web.tools.JsonHelp;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <ol>
 * date:11-8-18 editor:Yeqing
 * <li>创建文档</li>
 * <li>展示层Action基础接口/li>
 * </ol>
 * <ol>
 *
 * @author <a href="mailto:wsmbaiwo@126.com">YangHongJian</a>
 * @version 2.0
 * @since 1.6
 */
public class BaseAction {
    protected Logger log = Logger.getLogger(this.getClass());
    //返回dispatcher类型
    public static String SUCCESS = "success";
    public static String ERROR = "error";

    //返回不带code的json类型，注意要对strJson赋�?
    public static String AJAX_NO_CODE = "ajaxnocode";
    protected String strJson = "Operation was successful";

    //返回带code的json类型，注意要对mapJsonData赋�?
    public static String AJAX_CODE = "ajaxcode";
    protected int code = 0;
    protected String msg = "";

    public String getExpMsg() {
        return expMsg;
    }

    public void setExpMsg(String expMsg) {
        this.expMsg = expMsg;
    }

    protected String expMsg = "";
    

    protected List list = new ArrayList();
    protected Map mapParam = new HashMap();
    
    //放置数据
    protected Map model = new HashMap();

    public Map getModel()
	{
		return model;
	}

	public void setModel(Map model)
	{
		this.model = model;
	}

	public BaseAction() {
    }

    /**
     * 从表单中获取返回视图类型(RESULT_TYPE)
     *
     * @return 默认返回 success
     */
    public String getResult() {
        //保存数据
       // JsonHelp.getRequest().setAttribute("data",resultMapData);
        String result = JsonHelp.getReqParamVal("RESULT_TYPE");
        return result.length() == 0 ? SUCCESS : result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

   

    public String getStrJson() {
        return strJson;
    }

    public void setStrJson(String strJson) {
        this.strJson = strJson;
    }
    
    public void addMessage(int code) {
        
    }
    
    public void addMessage(int code,String msg) {
    	this.code=code;
        this.msg=msg;
    }

    public String getExceptionMessage(Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        return sw.toString().replace("\r\n", "<br>");
    }

    
}
